<!DOCTYPE html>
<html>
<head>
    <title>常量属性生成</title>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<style>
    input, textarea {
        width: 400px;
    }

    #result, #data {
        height: 400px;
    }
</style>
<body>

<table>
    <tr>
        <td>内容</td>
        <td>
            <textarea type="text" id="data"></textarea>
        </td>

    </tr>
    <tr>
        <td>结果</td>
        <td>
            <textarea id="result"></textarea>
        </td>
    </tr>

</table>
<button onclick="generate()">生成</button>
<script type="text/javascript">
    String.prototype.format = function()
    {
        var args = arguments;
        return this.replace(/\{(\d+)\}/g,
                function(m,i){
                    return args[i];
                });
    }
    function generate() {
        var data = $("#data").val();
        var strArr = data.split("\n");
        var items = new Array();
        var result = "";
        var template='public static final String {0} = "{1}";\n        @DatabaseField(columnName = "{1}")\n        @SerializedName("{1}")\n        int {2};';
        for (var index in strArr) {
            var field=strArr[index];
            var upperCase=field.toUpperCase();
            var afterConvert = field.replace(/\-(\w)/g, function (all, letter) {
                return letter.toUpperCase();
            });
            var afterFormat=template.format(upperCase,field,afterConvert);
            result+=afterFormat+"\n";
        }
        $("#result").val(result);
    }
</script>
</body>
</html>

